<template>
  <div class='container'>
    <el-dialog
  title="新增学科"
  :visible="dialogVisible"
  width="30%"
  @close="closeFn"
  >
  <div style="display: flex">
  学科名称
  <el-input
  style="width: 280px"
    placeholder="请输入学科名称"
    v-model="list.subjectName">
  </el-input>
  </div>
  是否显示
  <el-switch
  v-model="list.isFrontDisplay"
  active-color="#13ce66"
  inactive-color="#ff4949">
</el-switch>
  <span slot="footer" class="dialog-footer">
    <el-button @click="closeFn">取 消</el-button>
    <el-button type="primary" @click="submit">确 定</el-button>
  </span>
</el-dialog>
  </div>
</template>

<script>
import { add } from '@/api/hmmm/subjects.js'
export default {
  props: {
    dialogVisible: {
      type: Boolean,
      required: true
    }
  },
  data () {
    return {
      list: {
        subjectName: '',
        isFrontDisplay: true
      }
    }
  },
  methods: {
    closeFn () {
      this.$emit('update:dialogVisible', false)
    },
    async submit () {
      if (this.list.isFrontDisplay === true) {
        this.list.isFrontDisplay = 1
      } else {
        this.list.isFrontDisplay = 0
      }
      await add(this.list)
      // console.log(res)
      this.$message.success('添加成功')
      this.closeFn()
      this.$emit('addFn')
    }
  }
}

</script>

<style scoped lang='less'></style>
